from django.db import models

# Create your models here.
from dvadmin.utils.models import CoreModel


class ProjectManageModel(CoreModel):
    project_name = models.CharField(max_length=50, verbose_name='项目名称', unique=True, help_text='项目名称')
    project_key = models.CharField(max_length=50, verbose_name='项目标识', unique=True, help_text='项目标识')
    status = models.BooleanField(default=True, verbose_name='项目状态', help_text='项目状态')
    owner = models.CharField(max_length=10, verbose_name='项目负责人', blank=True, null=True, help_text='项目负责人')

    class Meta:
        db_table = 'project'
        verbose_name = '项目信息'
        verbose_name_plural = verbose_name
        ordering = ('-update_datetime',)


class DefectManageModel(CoreModel):
    defect_des = models.CharField(max_length=100, verbose_name='缺陷描述', help_text='缺陷描述')
    priority = ((0, '高'), (1, '中'), (2, '低'),)
    defect_priority = models.IntegerField(choices=priority, default=2, verbose_name='缺陷优先级', help_text='缺陷优先级')
    level = ((0, 'S'), (1, 'A'), (2, 'B'), (3, 'C'), (4, 'D'),)
    defect_level = models.IntegerField(choices=level, default=4, verbose_name='缺陷等级', help_text='缺陷等级')
    status = ((0, '创建'), (1, '未处理'), (2, '处理中'), (3, '已解决'), (4, '搁置'),)
    defect_status = models.IntegerField(choices=status, default=0, verbose_name='缺陷状态', help_text='缺陷状态')
    defect_type = models.CharField(max_length=50, verbose_name='缺陷类型', help_text='缺陷类型')
    reproduce_step = models.CharField(max_length=255, verbose_name='重现步骤', blank=True, null=True, help_text='重现步骤')
    tester = models.CharField(max_length=10, verbose_name='测试人员', blank=True, null=True, help_text='测试人员')
    developer = models.CharField(max_length=10, verbose_name='开发人员', blank=True, null=True, help_text='开发人员')
    accident_time = models.DateField(verbose_name='缺陷产生时间', blank=True, null=True, help_text='缺陷产生时间')
    resolution_time = models.DateField(verbose_name='缺陷解决时间', blank=True, null=True, help_text='缺陷解决时间')
    cause_occurrence = models.CharField(max_length=255, verbose_name='产生原因', blank=True, null=True, help_text='产生原因')
    improvement_action = models.CharField(max_length=255, verbose_name='预防措施', blank=True, null=True, help_text='预防措施')
    effect_range = models.CharField(max_length=255, verbose_name='影响范围', blank=True, null=True, help_text='影响范围')
    project_belong = models.ForeignKey(
        to='ProjectManageModel',
        null=True,
        blank=True,
        default=None,
        verbose_name='所属项目',
        db_constraint=False,
        on_delete=models.PROTECT,
        help_text='所属项目')
    module_belong = models.ForeignKey(
        to='test_manage.CaseModuleModel',
        verbose_name='所属模块',
        db_constraint=False,
        null=False,
        on_delete=models.PROTECT,
        help_text='所属模块')

    class Meta:
        db_table = 'defect'
        verbose_name = '缺陷信息'
        verbose_name_plural = verbose_name
        ordering = ('-create_datetime',)
